Skip to content

bpo-30899: IDLE: Add idle config parser unittest #2662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 12, 2017

Conversation

mlouielu
Copy link
Contributor

No description provided.

@mention-bot
Copy link

@mlouielu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terryjreedy to be a potential reviewer.

@mlouielu mlouielu changed the title bpo-30899: Add idle config parser unittest bpo-30899: IDLE: Add idle config parser unittest Jul 11, 2017
Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without looking at the classes, looking good.

self.assertEqual(parser.GetOptionList('not exist'), [])

def test_load_file(self):
config_path = support.findfile('cfgparser.1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a file in test dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, borrow from test_configparser.py

@@ -3,6 +3,9 @@
Much is tested by opening config dialog live or in test_configdialog.
Coverage: 27%
'''
import os
import tempfile
from test import support
from test.support import captured_stderr
Copy link
Member

@terryjreedy terryjreedy Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One style or other, not both. Either add findfile to second or 'support.' to 'captured_stderr' wherever it is. EDIT: fixed.

one = a string
two = true
three = false
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly redundant, but OK as is.

self.assertEqual(parser.Get('two', 'two'), 'true')
self.assertEqual(parser.Get('two', 'three'), 'false')
self.assertEqual(parser.Get('not', 'exist'), None)
self.assertEqual(parser.Get('not', 'exist', default='DEFAULT'), 'DEFAULT')
Copy link
Member

@terryjreedy terryjreedy Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done with a subtest with 5 cases and a subtest with 4 cases and the remaining test. But I think it not worthwhile here. What I have done in situations like this and would like to do here is to name the bound method, "equal = self.assertEqual", and then use that: "equal(parser.Get(...., False)". It is then easier to focus on what is being compared.
EDIT: fixed (eq is fine).

eq = self.assertEqual

# Test with type
eq(parser.Get('one', 'one', type='bool'), False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use assertIs(). Since False and True are singletons, this tests both type and value. Otherwise parser.Get() returning 0 will pass the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us see whether configparser passes the stricter test.

eq(parser.Get('two', 'three'), 'false')

# If option not exist, should return None, or default
eq(parser.Get('not', 'exist'), None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertIsNone()

Copy link
Member

@terryjreedy terryjreedy Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed here and below.


parser.AddSection('Foo')
parser.AddSection('Bar')
self.assertEqual(parser.IsEmpty(), True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertTrue().

Or assertIs() if you want to check that exact bool is returned. But I think this is redundant.

parser.AddSection('Foo')
parser.AddSection('Bar')
parser.SetOption('Foo', 'bar', 'false')
self.assertEqual(parser.IsEmpty(), False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertFalse().


# Set option to not exist section should create section and return True
self.assertEqual(parser.SetOption('Bar', 'bar', 'true'), True)
self.assertEqual(sorted(parser.sections()), ['Bar', 'Foo'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assertCountEqual().

Copy link
Member

@terryjreedy terryjreedy Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a looser test, but I read the doc, as it is new to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using assertCountEqual() is OK, ConfigParser were using assertEqual to test, we only need to care about the item is correct or not here.

parser.AddSection('Foo')
parser.SetOption('Foo', 'bar', 'true')

self.assertEqual(parser.RemoveOption('Foo', 'bar'), True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertTrue()/assertFalse()

@terryjreedy
Copy link
Member

Serhiy, thanks for the review. I still have to remember to use the specific tests. I think the code reads better.

@terryjreedy
Copy link
Member

terryjreedy commented Jul 12, 2017

Louie, I think this is ready to merge and plan to do so tomorrow. Review changes if you can. I re-ordered the functions in one of the classes and corresponding test class so the order makes sense and is the same in both. So the actual change is less drastic than it might look at first. If I had thought about it, I might have done the re-order in a separate commit. I added a few test to complete coverage.

@mlouielu
Copy link
Contributor Author

@terryjreedy I take a brief look and seems good. I'll take the deep review today.

@mlouielu
Copy link
Contributor Author

@terryjreedy Fix some comment and the cfg_type_changed with unittest assert. Otherwise looks good.

@@ -26,6 +30,161 @@ def tearDownModule():
idleConf.userCfg = usercfg


class IdleConfParserTest(unittest.TestCase):
"""Test ththat IdleConfParser works"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@terryjreedy
Copy link
Member

Louie, you need to follow the same comment rule you have reminded Cheryl of.
# Capitalize first word, end with period.
It is great to have these two classes completely covered.

@terryjreedy terryjreedy merged commit 50c9435 into python:master Jul 12, 2017
terryjreedy pushed a commit to terryjreedy/cpython that referenced this pull request Jul 12, 2017
…arser subclasses. (pythonGH-2662)

Patch by Louie Lu.
(cherry picked from commit 50c9435)
terryjreedy added a commit that referenced this pull request Jul 12, 2017
…arser subclasses. (GH-2662) (#2685)

Patch by Louie Lu.
(cherry picked from commit 50c9435)
@mlouielu
Copy link
Contributor Author

Thanks @terryjreedy @csabella @serhiy-storchaka for reviewing this, learn a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants